<!DOCTYPE html>
<html lang="cn" class="app fadeInUp animated">
<head>
  <meta charset="utf-8"/>
  <title>{$_SERVER['WEB_NAME']}—国内最专业的小程序管理平台</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
  <link href="/assets/stylesheets/bootstrap.min.css" rel="stylesheet"/>
  <link href="/assets/stylesheets/font-awesome.min.css" rel="stylesheet"/>
</head>

<body>

<div class="container-fluid" style="padding-top: 15px">
  <div class="row">
    <div class="col-md-12">
      <!--余额面板-->
      <div class="panel panel-default">
        <div class="panel-heading">
          充值
        </div>
        <div class="panel-body">
          <div class="form-group">
            <label for="money" class="control-label">充值金额：</label>
            <input type="text" class="form-control" id="money" name="money">
          </div>
          <div style="margin: 20px auto">
            <a href="javascript:void(0)" class="btn btn-success" id="btn-pay">
              <i class="fa fa-cny"></i>
              立即支付
            </a>
          </div>
          <div>
            <div><b>注意事项：</b></div>
            <div>1，充值最小单位为0.01元</div>
            <div>2，充值完成关闭窗口即可</div>
            <div>3，如果充值金额未及时刷新出来，稍等几分钟即可</div>
          </div>
        </div>
        <div class="panel panel-default" id="qrcode-box" style="display: none">
          <div class="panel-heading">
            微信扫码支付
          </div>
          <div class="panel-body" style="text-align: center">
            <div>
              <img src="" alt="" width="256" height="256" id="pay-qrcode">
            </div>
            <div>
              扫码支付完成后，关闭窗口即可（二维码有效时间2小时）
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

<script src="/mix/jquery.min.js"></script>
<script src="/mix/layer.js"></script>
<script>
  $('#btn-pay').on('click', function () {
    var money = $('#money').val();
    if (isNaN(money) || money <= 0) {
      layer.msg('请输入正确的金额数字');
      return false;
    }
    //发起支付请求，获取二维码链接
    var img_qrcode_box = $('#qrcode-box');
    var img_qrcode = $('#pay-qrcode');
    $.ajax({
      url: 'recharge.html',
      method: 'post',
      data: {
        'money': money
      },
      beforeSend: function () {
        layer.load();
      },
      success: function (resp) {
        resp = JSON.parse(resp);
        console.log(resp);
        if (resp.status == 'success') {
          img_qrcode.attr('src', resp.data);
          img_qrcode_box.show(500);
        } else {
          layer.msg(resp.msg)
        }
      },
      error: function () {
        layer.msg('网络服务器错误，请稍后重试');
      },
      complete: function () {
        layer.closeAll('loading');
      }
    });
  })
</script>

</body>

</html>
